export default class RequestSpotHolder {
  #holder = []

  push (data) {
    this.#holder.push(data)
  }

  clear () {
    this.#holder.length = 0
  }

  get length () {
    return this.#holder.length
  }

  recover (request) {
    this.#holder.forEach(({
      requestParams: {
        method,
        url,
        data,
        header
      },
      resolve,
      reject,
      target
    }) => {
      if (resolve) {
        request.call(target, method, url, data, header).then(resolve).catch(reject)
      }
    })
    this.clear()
  }
}